<template>
  <div>
    <el-form class="query-table-form" :inline="true">
      <el-form-item>
        <select-address
          v-model="params.address_code"
          placeholder="地址查询"
          clearable
          :auto-top="true"
          @change="getData()"
        ></select-address>
      </el-form-item>
      <el-form-item>
        <el-input
          v-model="params.customer_name"
          placeholder="企业名称查询"
          :clearable="true"
          @keyup.native.enter="getData()"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-input
          v-model="params.corp_name"
          placeholder="负责人查询"
          :clearable="true"
          @keyup.native.enter="getData()"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getData()">查询</el-button>
      </el-form-item>
      <el-form-item class="float-right">
        <el-button
          icon="el-icon-download"
          type="primary"
          :loading="exportLoading"
          @click="exportExcel('项目管理：受理项目库')"
        >
          导出
        </el-button>
      </el-form-item>
    </el-form>
    <c-table border class="table-sm" v-loading="loading" :columns="tableColumns" :data="tableData">
      <template v-slot:address="scope">
        <div class="text-truncate" :title="scope.row.address">{{ scope.row.address }}</div>
      </template>
      <template v-slot:useDir="scope">
        <div class="text-truncate" :title="scope.row.funds_use_dir">
          {{ scope.row.funds_use_dir }}
        </div>
      </template>
      <template v-slot:itemStatus="scope">
        <span class="badge" :class="`badge-${scope.row.itemStatusStyle}`">
          {{ scope.row.itemStatusLabel }}
        </span>
      </template>
    </c-table>
    <div class="query-pagination">
      <div></div>
      <el-pagination
        layout="total, prev, pager, next, jumper"
        :current-page.sync="params.index"
        :page-size="params.size"
        :total="tableCount"
        @current-change="getData"
      ></el-pagination>
    </div>

    <el-dialog
      :visible.sync="reportVisible"
      :close-on-click-modal="false"
      append-to-body
      top="30px"
      width="80%"
    >
      <el-tabs v-model="active">
        <el-tab-pane label="数字档案卡" name="file">
          <credit-file :query-id="queryId" :viewMode="true"></credit-file>
        </el-tab-pane>
        <el-tab-pane label="政府推荐函" v-if="+relatedData.submit_type === 1">
          <recommend-file :related-data="relatedData"></recommend-file>
        </el-tab-pane>
        <el-tab-pane label="附件">
          <attach-view :queryId="queryId" :visible="reportVisible"></attach-view>
        </el-tab-pane>
      </el-tabs>
    </el-dialog>

    <credit-edit :visible.sync="creditVisible" :queryId="creditId"></credit-edit>
    <approval-edit
      :visible.sync="approvalVisible"
      @success="handleSuccess"
      :formData="formData"
    ></approval-edit>
  </div>
</template>

<script>
import taskTableMixin from '@/bank/mixin/taskTable'
import CreditFile from '@/bank/components/creditFile/index'
import CreditEdit from '@/bank/components/creditFile/CreditDialog'
import RecommendFile from '@/credit/views/city/program/RecommendFile'
import AttachView from '@/credit/components/AttachView'
import SelectAddress from '@/components/select/SelectAddress'
import ApprovalEdit from '@/bank/views/program/ApprovalEdit'
import { mapGetters } from 'vuex'
export default {
  components: {
    SelectAddress,
    CreditFile,
    CreditEdit,
    RecommendFile,
    AttachView,
    ApprovalEdit,
  },
  mixins: [taskTableMixin],
  props: {},
  data() {
    return {
      order: {
        N2is_approval: 'asc',
        N1claim_status: 'asc',
      },
      params: {
        index: 1,
        size: 15,
        address_code: '',
        'gua_type.in': '0,1,2,4',
        'orWhere.public_bank_ids.is': 'null',
        'recommend_status.eq': 1,
        'claim_status.eq': 0,
      },
      tableName: 'customer_related',
      tableCount: 0,
      tableData: [],
      tableColumns: [
        {
          attrs: { label: '项目名称', prop: 'customer_name', minWidth: '110px' },
          process: (v, row) => ({
            attrs: { class: 'project-history', attrs: { 'data-history': row.is_history } },
          }),
        },
        // { attrs: { label: '受理类型', prop: 'project_type', align: 'center' } },
        { attrs: { label: '地址', prop: 'address' }, slot: 'address' },
        { attrs: { label: '负责人', prop: 'corp_name', align: 'center' } },
        { attrs: { label: '联系电话', prop: 'mobile_no', align: 'center' } },
        { attrs: { label: '申请金额(万元)', prop: 'apply_funds', align: 'center' } },
        { attrs: { label: '资金用途', prop: 'funds_use_dir' }, slot: 'useDir' },
        {
          attrs: { label: '项目状态', prop: 'itemStatusLabel', align: 'center' },
          slot: 'itemStatus',
        },
        {
          attrs: { label: '操作', align: 'center', minWidth: '100' },
          operations: [
            {
              content: '受理',
              icon: 'fa fa-gavel',
              event: this.handleEdit,
            },
            { content: '数字信用档案', icon: 'fa fa-file-text', event: this.handleCreditEdit },
            { content: '查看', icon: 'fa fa-search', event: this.handleView },
          ],
        },
      ],
      reportVisible: false,
      relatedData: {},
      active: 'file',
      queryId: '',
      creditVisible: false,
      creditId: '',
      formData: {},
      approvalVisible: false,
    }
  },
  computed: {
    ...mapGetters(['org', 'user']),
  },
  watch: {},
  mounted() {},
  created() {
    this.params.address_code = this.$utils.getAddressCode()
    this.params['orWhere.public_bank_ids.like'] = this.clientId
    // this.params['orWhere.bank_code.endlike'] = this.org.orgCode
    this.getData()
  },
  methods: {
    handleSuccess() {
      this.$emit('success', true)
      this.getData(this.params.index)
    },
    handleView(row) {
      this.active = 'file'
      this.queryId = row.customer_related_id
      this.reportVisible = true
      this.relatedData = row
    },
    handleCreditEdit(row) {
      this.creditVisible = true
      this.creditId = row.customer_related_id
    },
    handleEdit(row) {
      this.formData = row ? { ...row } : {}
      this.formData.approval_load_years = this.formData.approval_load_years
        ? this.formData.approval_load_years
        : this.formData.load_years
      this.formData.bank_approved_person_mobile = this.formData.bank_approved_person_mobile
        ? this.formData.bank_approved_person_mobile
        : this.user.phoneNumber
      this.formData.bank_approved_person = this.formData.bank_approved_person
        ? this.formData.bank_approved_person
        : this.user.realName
      this.formData.bank_approved_funds = this.formData.bank_approved_funds
        ? this.formData.bank_approved_funds
        : this.formData.apply_funds
      this.approvalVisible = true
    },
    dataAdapter(item) {
      // if (this.org.orgCode.includes(item.bank_code) && +item.submit_type === 5) {
      //   item.project_type = '自建项目'
      // } else if (this.clientId.includes(item.public_bank_ids)) {
      //   item.project_type = '推荐项目'
      // } else {
      //   item.project_type = '受理项目'
      // }
      if (+item.claim_status === 0) {
        item.itemStatusLabel = '未受理'
        item.itemStatusStyle = 'warning'
      } else {
        item.itemStatusLabel = '已受理'
        item.itemStatusStyle = 'success'
      }

      return item
    },
  },
}
</script>
<style lang="scss" scoped></style>
